extends Node2D
@onready var map: TileMap = $map
const ENEMY = preload("res://enemy/enemy.tscn")
var map_size = 0
@onready var enemy_spawn_timer = $enemy_spawn_timer
var enemies = []

func spwan_enemy():
	var rand = randi_range(0,map_size-1)
	var enemy = ENEMY.instantiate()
	enemy.position = map.map_to_local(map.get_used_cells(0)[rand])*6
	add_child(enemy)
	enemies.append(enemy)
	enemy_spawn_timer.start()

func spwan_map():
	for cell in map.get_used_cells(0):
		if randi_range(0,100)<=3:
			map.set_cell(1,cell,2,Vector2i(5,2))
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	map_size = map.get_used_cells(0).size()
	spwan_map()
	spwan_enemy()
	$status_ui.timer_start()
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass


func _on_enemy_spawn_timer_timeout():
	spwan_enemy()
	pass # Replace with function body.


func _on_upgrade_panel_continue_game():
	get_tree().paused = false
	pass # Replace with function body.


func _on_upgrade_panel_pause_game():
	get_tree().paused = true
	pass # Replace with function body.


func _on_status_ui_count_time_out():
	for enemy in enemies:
		if enemy != null:
			enemy.killed()
	pass # Replace with function body.
